﻿
Imports elpmis

Public MustInherit Class _cacheProcessor
    Inherits cacheProcessor

    Private path As String = Nothing
    Private cache As Int64 = 0
    Private _cacheType As cachetypeEnum = cachetypeEnum.lang_urlfull

    Protected MustOverride Function app() As lpmsmonitor

    Public NotOverridable Overrides Sub initial(Optional ByVal config As configParser = Nothing)
        MyBase.initial(config)
    End Sub

    Protected NotOverridable Overrides Function cachetype() As cachetypeEnum
        Return _cacheType
    End Function

    Public NotOverridable Overrides Function pathidentity() As String
        Dim rtn As String = Nothing
        If lpmsmonitor.invokepath(app(), rtn) Then
            Return rtn
        Else
            Return path
        End If
    End Function

    Protected NotOverridable Overrides Function normalRetiredTicks() As Int64
        Dim rtn As Int64 = Nothing
        If lpmsmonitor.invokecache(app(), rtn) Then
            Return rtn
        Else
            Return cache
        End If
    End Function

#If RETIRED Then
    Protected NotOverridable Overrides Sub addresponseHeaders(ByVal context As httpContext)
        lpmsmonitor.invokeheader(app(), context)
    End Sub
#End If

    Protected NotOverridable Overrides Function processImpl(ByVal context As httpContext) As Boolean
        Return lpmsmonitor.invokeprocess(app())
    End Function

    Protected Sub New(ByVal path As String, ByVal cache As Int64, ByVal cacheType As cachetypeEnum)
        MyBase.New()
        copy(Me.path, path)
        copy(Me.cache, cache)
        copy(Me._cacheType, cacheType)
    End Sub

    Protected Sub New(ByVal path As String, ByVal cache As Int64)
        Me.New(path, cache, cachetypeEnum.lang_urlfull)
    End Sub
End Class

Public Class nameCacheProcessor
    Inherits _cacheProcessor

    Private name As String = Nothing

    Public Sub New(ByVal name As String, ByVal path As String, ByVal cache As Int64, ByVal cacheType As cachetypeEnum)
        MyBase.New(path, cache, cacheType)
        copy(Me.name, name)
    End Sub

    Public Sub New(ByVal name As String, ByVal path As String, ByVal cache As Int64)
        Me.New(name, path, cache, cachetypeEnum.lang_urlfull)
    End Sub

    Protected Overrides Function app() As lpmsmonitor
        Return findlpmsengine(name)
    End Function
End Class

Public Class scriptCacheProcessor
    Inherits _cacheProcessor

    Private script As String = Nothing

    Public Sub New(ByVal path As String, ByVal cache As Int64, ByVal script As String, ByVal cacheType As cachetypeEnum)
        MyBase.New(path, cache, cacheType)
        copy(Me.script, script)
    End Sub

    Public Sub New(ByVal path As String, ByVal cache As Int64, ByVal script As String)
        Me.New(path, cache, script, cachetypeEnum.lang_urlfull)
    End Sub

    Protected Overrides Function app() As lpmsmonitor
        Return lpmsengine(script)
    End Function
End Class